<template>
  <div class="contain">
  <dv-scroll-board
  :config="warning" style="position: relative;width:98%;" class="warning" />
</div>
</template>

<script>
import axios from 'axios';
import warningImg from '../assets/images/warning.png';

export default {
  data() {
    return {
      warning: {
        header: ['状态','科室', '床位','姓名'],
        columnWidth: ['25%', '25%', '25%', '25%'],
        headerBGC: "#000e1d",
        headerHeight: 50,
        data: [],
        align: ['center'],
        evenRowBGC: "#000e1d",
        oddRowBGC: "#1d2746",
        indexHeader: '',
        index: true,
        carousel: 'page',
        hoverPause: true,
        rowNum: 5,
        isHtml: true,
      },
      rank: 0,
      heart: 0,
      pressure: 0,
      pressureDisplay: '血压',
      rawPatientData: [],
    };
  },
  async mounted() {
    try {
      // 从localStorage获取医生手机号
      const doctorPhone = localStorage.getItem('doctorPhone');
      
      // 向后端发送请求获取所有患者数据
      const res = await this.$axios.get('/getAllPatientStatus');
      
      // 检查响应结构并提取数据
      let patientData = [];
      if (res.data && res.data.code === 200 && res.data.data) {
        patientData = res.data.data;
      } else if (Array.isArray(res.data)) {
        // 如果直接返回数组
        patientData = res.data;
      } else {
        this.warning.data = [['-', '-', '-', '-']];
        return;
      }
      
      // 根据医生手机号和状态过滤数据
      const filteredData = patientData.filter(item => 
        item.status === "警告" && (!doctorPhone || item.doctorPhone === doctorPhone)
      );
      
      this.rawPatientData = filteredData;

      this.warning.data = filteredData.map(item => [
      `<div class="status-cell">
          <img src="${this.getStatusImage('警告')}"
               style="width:20px;height:20px;vertical-align:middle;"
               alt="警告">
        </div>`,
        item.department || '-',
        item.bedNumber || '-',
        item.patientName || '-',
      ]);
      this.warning = { ...this.warning };
    } catch (error) {
      this.warning.data = [['-', '-', '-', '-']];
    }
  },
  methods: {
    getStatusImage(status) {
      switch(status) {
        case '危险':
          return dangerousImg;
        case '警告':
          return warningImg;
        default:
          return null;
      }
    },
    handleRowHover({ rowIndex }) {
      const patient = this.rawPatientData[rowIndex];
      if (patient) {
        // 这里可以根据需要添加悬停时的逻辑
        // 例如显示更详细的患者信息
      }
    },
    handleRowLeave() {
      this.rank = 0;
      this.heart = 0;
      this.pressure = 0;
      this.temperatureDisplay = '体温';
      this.pressureDisplay = '血压';
    }
  }
};
</script>

<style>
.contain{
  position: relative;
  width: 96%;
  height: 96%;
  overflow: hidden;
}

.dv-scroll-board {
  position: absolute;
  left: 1%;
  right: 1%;
  height: 90% !important;
  padding: 2%;
}
</style>